package mest.service.hws.impl;

import com.alibaba.fastjson.JSON;
import mest.dao.hws.plan_productjob_purchaseMapper;
import mest.entity.plan_productjob_purchase;
import mest.entity.plan_productjob_purchase_record;
import mest.entity.warehouse_productjob_purchase;
import mest.service.hws.plan_productjob_purchaseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
* 计划采购单内容
* */
@Service
public class plan_productjob_purchaseServiceimpl implements plan_productjob_purchaseService {

    @Resource
    private plan_productjob_purchaseMapper ppp;

    //批量新增plan_productjob_purchaseMapper内容表
    @Override
    public int insert(String theirDb,
                         List<plan_productjob_purchase> record) {
        //
       int count;
       System.out.println("进入增删改方法");
       Map<String, Object> map = new HashMap<String, Object>();
       try {
           count = ppp.insert(theirDb,record);
       }catch (Exception e){
           count = 0;
        System.out.println(e.toString());
    }
       return count;
    }


    //根据id查询单个数据
    @Override
    public String selectByPrimaryKey(String theirDb,
                                     Integer id) {
        /* selectById  selectAll  */
        System.out.println("进入查询");
        Map<Object,Object> map = new HashMap<Object,Object>();
        try {
                map.put("code",0);
                map.put("msg","查询成功");
                map.put("count",(ppp.selectByPrimaryKey(theirDb,id)==null)?0:1);
                map.put("data",ppp.selectByPrimaryKey(theirDb,id));
        }catch (Exception e){
                System.out.println(e.toString());
                map.put("code",1);
                map.put("msg","查询失败");
                map.put("errmsg",e.toString());
        }
        return JSON.toJSONString(map);
    }

    //根据ppid和状态查询计划单关联的内容对象集合
    @Override
    public String selectPrimary(String theirDb,
                                Integer limit, Integer page, Integer ppId, Integer status) {
        /* selectById  selectAll  */
        System.out.println("进入查询");
        Map<Object,Object> map = new HashMap<Object,Object>();
        try {
                map.put("code",0);
                map.put("msg","查询成功");
                map.put("count",ppp.selectcount(theirDb,ppId, status));
                map.put("data",ppp.selectPrimary( theirDb,limit,  (page-1)*limit,  ppId,  status));
        }catch (Exception e){
                System.out.println(e.toString());
                map.put("code",1);
                map.put("msg","查询失败");
                map.put("errmsg",e.toString());
        }
        return JSON.toJSONString(map);
    }


    //更新数量，供应商，状态
    @Override
    public String updateByPrimaryKey(String theirDb,
                                     plan_productjob_purchase record) {
        /*/insertModel /delModel /updateByone*/
        System.out.println("进入增删改方法");
        Map<String, Object> map = new HashMap<String, Object>();
        try {
                map.put("code", 0);
                map.put("msg", "操作成功");
                map.put("count", ppp.updateByPrimaryKey(theirDb,record));
        }catch (Exception e){
            map.put("code", 1);
            map.put("msg", "操作失败");
            System.out.println(e.toString());
        }    
        return JSON.toJSONString(map);
    }

    @Override
    public int updateByone(String theirDb,
                           List<plan_productjob_purchase_record> record) {
        return ppp.updateByone(theirDb,record);
    }

}
